#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    //字符串赋值的方式
    string str_1 = "hello";
    string str_2("hello");
    string str_3(str_2);
    string str_4(10 ,'a');

    cout << "str_1 = " << str_1 << endl;
    cout << "str_2 = " << str_2 << endl;
    cout << "str_3 = " << str_3 << endl;
    cout << "str_4 = " << str_4 << endl;

    //字符串的拼接方式
    str_4 = str_1 + str_2 ;
    cout <<"str_4 = " << str_4 << endl;
    
    str_4.append("ppp");
    cout << "str_4 = " << str_4 << endl;
    str_4.append(10 ,'a');
    cout << "str_4 = " << str_4 << endl;

    //字符串的查找 
    size_t pos = str_4.find("ppp");
    cout << "ppp在" << pos <<"的位置" << endl;
    
    //字符串的替换
    str_4.replace(pos , 3 , "hhh");
    cout << "str_4 = " << str_4 << endl;
    
    //字符串的比较
    if (str_1 == str_2)
    {
        cout << "两个字符串一样" << endl;
    }
    
    //字符串存取
    char ch_1 =str_1[0];
    char ch_2 =str_1.at(1);
    cout << "str_1[0] = " << ch_1 << " str_1.at(1)"<< endl;

    //字符串的插入
    str_4.insert(13 , "niubi");
    cout <<"str_4 = " << str_4 << endl;

    //字符串的删除
    str_4.erase(13,5);
    cout <<"str_4 = " << str_4 << endl;

    //字符串清空
    str_4.clear();
    cout << "str_4 = " << str_4 << endl;

    //字符串的转换C风格 转C++

    //C++ 转C风格
    const char * str_c = str_1.c_str();
    cout << "str_c = " << str_c << endl;

    return 0;
}
